package mvp.com.bbc.ui.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import java.util.ArrayList;
import java.util.List;

import mvp.com.bbc.R;
import mvp.com.bbc.appContact.AppContact;
import mvp.com.bbc.base.BaseFragment;
import mvp.com.bbc.base.BaseFragmentPagerAdapter;
import mvp.com.bbc.bean.ArtListBean;
import mvp.com.bbc.di.component.DaggerArtListNameComponent;
import mvp.com.bbc.di.modules.ArtListNameModules;
import mvp.com.bbc.ui.presenter.ArtListNamePresenter;

/**
 * Created by Administrator on 2017/9/29.
 */

public class MyPersonFragment extends BaseFragment implements AppContact.ArtListNameView {


    private TabLayout mTab;
    private ViewPager vp;
    private ImageView ivVis;
    private AppBarLayout appBarLayou;

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_qiubeaufy_hotmom;
    }

    @Override
    protected void initView(View view, Bundle savedInstanceState) {
        mTab = (TabLayout) view.findViewById(R.id.tablelayout);
        vp = (ViewPager) view.findViewById(R.id.scroll_view_pager);
        ivVis = (ImageView) view.findViewById(R.id.iv_visible);
        appBarLayou = (AppBarLayout) view.findViewById(R.id.appBarLayou);
        ArtListNamePresenter presenter = DaggerArtListNameComponent.builder()
                .artListNameModules(new ArtListNameModules(this))
                .build()
                .getPresenter();
        presenter.artListNamePresemter();
    }

    @Override
    public void artListNameView(ArtListBean artListBean) {
        List<ArtListBean.TeBean> te = artListBean.getTe();
        if (te != null && te.size() > 0) {
            for (int i = 0; i < te.size(); i++) {
                String[] title = new String[]{te.get(0).getName(), te.get(1).getName(), te.get(2).getName()};
                List<Fragment> fragments = new ArrayList<>();
                fragments.add(ArtListFragment1.newInstance("1", appBarLayou));
                fragments.add(ArtListFragment1.newInstance("2", appBarLayou));
                fragments.add(ArtListFragment1.newInstance("3", appBarLayou));
                BaseFragmentPagerAdapter pagerAdapter = new BaseFragmentPagerAdapter(getChildFragmentManager(), title, fragments);
                vp.setAdapter(pagerAdapter);
                mTab.setupWithViewPager(vp);
            }
        } else {
            ivVis.setVisibility(View.VISIBLE);
        }
    }
}
